<?php
include_once 'config.php';

function connect(){
    $con=mysqli_connect(HOST,USER,PWD);
    query('use new',$con);
    return $con;
}
function query($sql,$link){
    $res = mysqli_query($link,$sql);
    if(!$res)
    die("执行错误：".mysqli_error($link));
    return $res;
}



function admin_display($res){
    if($res->num_rows==0) 
    $result=array();
    else
while($row = mysqli_fetch_all($res)){
    $result=$row;

}
    
    include_once 'admin_display.html';

}
function alertMes($mes,$url){
	echo "<script>
			alert('{$mes}');
			location.href='{$url}';
	</script>";
	die;
}

//图像缩放
function imgSize($img,$dw,$dh){
    $arr=getimagesize($img);
    $w=$arr[0];
    $h=$arr[1];
    $t=$arr[2];
    $m=$arr['mime'];
    switch($t){
        case 1:
            $imagecreate="imagecreatefromgif";
            $imageout="imagegif";
            break;
        case 2:
                $imagecreate="imagecreatefromjpeg";
                $imageout="imagejpeg";
                break;
        case 3:
                    $imagecreate="imagecreatefrompng";
                    $imageout="imagepng";
                    break;
    }
    $imgr=$imagecreate($img);
    if($w/$dw>$h/$dh){
        $b=$w/$dw;
    }else{
        $b=$h/$dh;
    }
    $dw2=floor($w/$b);
    $dh2=floor($h/$b);
    $dimgr=imagecreatetruecolor($dw2,$dh2);
    imagecopyresampled($dimgr,$imgr,0,0,0,0,$dw2,$dh2,$w,$h);
    $dir=dirname($img);
    $file=basename($img);
    $save=$dir.'/'.'size'.$file;
    $imageout($dimgr,$save);
}
?>
